﻿using System.Collections.Generic;
using System.Text;
using System.Data;
using PPI.Entities;
using PPI.WebConsumer;
using VMind.Global;

namespace PPI.Client.Logic
{
    public class LVendor_Project 
    {
        private static EVendor_Project SelectData(DataRow _DataRow)
        {
            EVendor_Project _Vendor_Project = new EVendor_Project();
            _Vendor_Project.ActualCost = ConvertHelper.Todouble(_DataRow["ActualCost"]);
            _Vendor_Project.ActualEndDate = ConvertHelper.ToDateTime(_DataRow["ActualEndDate"]);
            _Vendor_Project.ActualStartDate = ConvertHelper.ToDateTime(_DataRow["ActualStartDate"]);
            _Vendor_Project.Name = ConvertHelper.Tostring(_DataRow["Name"]);
            _Vendor_Project.ScheduledCost = ConvertHelper.Todouble(_DataRow["ScheduledCost"]);
            _Vendor_Project.ScheduledEndDate = ConvertHelper.ToDateTime(_DataRow["ScheduledEndDate"]);
            _Vendor_Project.ScheduledStartDate = ConvertHelper.ToDateTime(_DataRow["ScheduledStartDate"]);
            //_Vendor_Project.Status = new EProjectStatus(1);
            //_Vendor_Project.Type = new EProjectType(1);
            //_Vendor_Project.Vendor = LVendor.SelectData(ConvertHelper.ToInt32(_DataRow["VendorFK"]));
            _Vendor_Project.Vendor_ProjectId = ConvertHelper.ToInt32(_DataRow["Vendor_ProjectId"]);
            return _Vendor_Project;
        }
        
        public static List<EVendor_Project> SelectAll()
        {
            DataTable _dt = WVendor_Project.SelectAll().Tables[0]; 
            List<EVendor_Project> _VendorProjectList = new List<EVendor_Project>();
            EVendor_Project _VendorProject;
            foreach (DataRow dr in _dt.Rows)
            {
                _VendorProject = SelectData(dr);
                _VendorProject.Vendor = new EVendor(ConvertHelper.ToInt32(dr["VendorFK"]), ConvertHelper.Tostring(dr["Vendor_Name"]),"1");
                _VendorProjectList.Add(_VendorProject);
            }
            return _VendorProjectList;
        }

        private static List<EVendor_Project> SelectAllIdName(DataTable dt)
        {
            List<EVendor_Project> _VendorProjectList = new List<EVendor_Project>();
            EVendor_Project _VendorProject;
            foreach (DataRow dr in dt.Rows)
            {
                _VendorProject = new EVendor_Project(ConvertHelper.Toint(dr["Vendor_ProjectID"]), dr["Name"].ToString());
                _VendorProject.Vendor = new EVendor(ConvertHelper.ToInt32(dr["VendorFK"]));
                _VendorProjectList.Add(_VendorProject);
            }
            return _VendorProjectList;
        }

        public static List<EVendor_Project> SelectAllIdName()
        {
            DataTable dt = WVendor_Project.SelectAllIdName().Tables[0];
            return SelectAllIdName(dt);
        }
        public static List<EVendor_Project> SelectAllIdNameByVendor(int vendorID)
        {
            DataTable dt = WVendor_Project.SelectAllIdNameByVendor(vendorID).Tables[0];
            return SelectAllIdName(dt);
        }

    }
}
